package com.sharp.socket.io.service;

import com.sharp.socket.io.constant.ChatMessageConstant;
import com.sharp.socket.io.dao.mongo.po.TopicChatMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Title: SocketIoReceiveMessageService
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2020/9/22 16:08
 * @description Project Name: customer-robot
 * @Package: com.bhfae.customer.robot.service.live
 */
@Slf4j
@Service
public class LiveReceiveMessageService {
    @Resource
    private ShowMessageService showMessageService;

    public void receiveSubscribeMessage(TopicChatMessage message) {
        log.debug("接收到消息广播 {}", message);
        if (StringUtils.equals(message.getTopic(), ChatMessageConstant.CMD)) {
            handleCmdMessage(message);
        } else if (StringUtils.equals(message.getTopic(), ChatMessageConstant.BROADCAST)) {
            log.debug("处理系统广播消息{}", message);
            handleBroadcastMessage(message);
        } else {
            if (StringUtils.isNotBlank(message.getRoomId())) {
                log.debug("处理广播消息{}", message);
                handleMessage(message);
            }
        }
    }

    private void handleCmdMessage(TopicChatMessage message) {

    }

    private void handleBroadcastMessage(TopicChatMessage message) {
        showMessageService.broadcast(message);
    }

    private void handleMessage(TopicChatMessage message) {
        showMessageService.show(message.getUserId(), message);
    }
}
